set more off
clear all
cap log close
set scheme s1mono
cd "~/Dropbox/Farm Subsidies and Committees/PB R&R/"


use customer_code election_year_desc any_neg if election_year_desc >= 2009 & any_neg == 0 using "~/Dropbox/Farm Subsidies and Committees/analyses/collapsed", clear
drop any_neg

* mark orgs
merge m:1 customer_code using "~/Dropbox/Farm Subsidies and Committees/analyses/org_ids", keep(1) nogen

* collapse to get number of times appeared per year
bys customer_code election_year_desc: keep if _n == 1
gen obs = 1
collapse (sum) cnt_years = obs, by(customer_code)

* collapse to get number of customers for each count of years
gen obs = 1
collapse (sum) cnt_per_cnt = obs, by(cnt_years)

* get total and then shares
egen total_cnt = total(cnt_per_cnt)
gen shr_per_cnt = cnt_per_cnt/total_cnt

* save
export delimited years_appeared_raw.csv, replace
